package com.example.activity

import android.os.Bundle
import android.util.Log
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import kotlin.math.log

/**
 * Activity A跳转Activity B，再按返回键，生命周期执行的顺序？
 * 1.显示A：onCreate(A)->onStart(A)->onResume(A)
 * 2.A跳B：onPause(A)->onCreate(B)->onStart(B)->onResume(B)->onStop(A)
 *      下一个Activity执行了onResume后，前一个Activity才回执行onStop
 * 3.按返回键：onPause(B)->onRestart(A)->onStart(A)->onResume(A)->onStop(B)->onDestroy()
 *
 * 如果 ActivityB 为 dialog 式或者 半透明背景，生命周期执行的顺序？ A可见但是不能点击
 * onPause：可见但是不能点击
 * onStop：不可见
 * 1.显示A：onCreate(A)->onStart(A)->onResume(A)
 * 2.A跳B：onPause(A)->onCreate(B)->onStart(B)->onResume(B)
 * 3.按返回键：onPause(B)->onResume(A)->onStop(B)->onDestroy(B)
 *
 * A->B->C ，再按2次返回键盘？
 * 1.显示A：onCreate(A)->onStart(A)->onResume(A)
 * 2.A跳B：onPause(A)->onCreate(B)->onStart(B)->onResume(B)->onStop(A)
 * 3.B跳C：onPause(B)->onCreate(C)->onStart(C)->onResume(C)->onStop(B)
 * 4.按返回键：onPause(C)->onRestart(B)->onStart(B)->onResume(B)->onStop(C)->onDestroy(C)
 * 5.按返回键：onPause(B)->onRestart(A)->onStart(A)->onResume(A)->onStop(B)->onDestroy(B)
 *
 *
 *
 *
 *
 *
 */
class MainActivity : AppCompatActivity() {
    companion object{
        private const val TAG = "MainActivity"
    }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)
        Log.d(TAG, "onCreate: ")


    }

    override fun onStart() {
        super.onStart()
        Log.d(TAG, "onStart: ")
    }

    override fun onResume() {
        super.onResume()
        Log.d(TAG, "onResume: ")
    }

    override fun onPause() {
        super.onPause()
        Log.d(TAG, "onPause: ")
    }

    override fun onStop() {
        super.onStop()
        Log.d(TAG, "onStop: ")
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.d(TAG, "onDestroy: ")
    }

    override fun onRestoreInstanceState(savedInstanceState: Bundle) {
        super.onRestoreInstanceState(savedInstanceState)
        val string = savedInstanceState.getString("name")
        Log.d(TAG, "恢复数据:$string ")
    }

    override fun onSaveInstanceState(outState: Bundle) {
        super.onSaveInstanceState(outState)
        outState.putString("name","yaotianxue")
        Log.d(TAG, "保存数据: ")
    }
}